package test.gps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class DataListActivity extends Activity {
	private ListView TXTlist;
	public TextView Back;
	private FileHelper helper;
	List<Map<String, Object>> listItem = new ArrayList<Map<String, Object>>();
	SimpleAdapter adtDvcs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.nmeadata);
		Back = (TextView) findViewById(R.id.textViewback);
		TXTlist = (ListView) findViewById(R.id.listViewTXT);
		helper = new FileHelper(getApplicationContext());

		Back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		List<String> name = helper.getFolderName(); 
		for (int i = 0; i < name.size(); i++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("text", name.get(i));
			listItem.add(map);
		}
		update();
		TXTlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Map<String, Object> map = listItem.get(arg2);
				String name = (String) map.get("text");
				Intent intent = new Intent(DataListActivity.this,
						GPSMapActivity.class);
				intent.putExtra("foldername", name);
				startActivity(intent);

			}
		});

	}

	public void update() {
		adtDvcs = new SimpleAdapter(this, listItem, R.layout.filelist,
				new String[] { "text" }, new int[] { R.id.textView1 });
		TXTlist.setAdapter(adtDvcs);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.data_list, menu);
		return true;
	}

}
